/**
 * Created with IntelliJ IDEA.
 * User: mkadush
 * Date: 12.09.13
 * Time: 12:28
 * To change this template use File | Settings | File Templates.
 */


var offsetAnchor = '-300';


//var saveButton = {
//    xtype: 'button',
//    id: 'saveButton',
//    text: 'сохранить',
//    handler: onButtonSaveClick
//};


//---------------------------------------------------------------
// People Form
//---------------------------------------------------------------

Ext.QuickTips.init();
var tabs = [
    {
        xtype: 'container',
        layout: 'form',
        title: 'Professional',
        style: 'padding:5px 5px 0',
        defaults: {
            xtype: 'textfield',
            width: 150
        },
        items: [
            {
                fieldLabel: 'Position',
                name: 'position',
                allowBlank: false
            },
            {
                xtype: 'numberfield',
                fieldLabel: 'Salary',
                name: 'salary'
            },
            {
                xtype: 'datefield',
                fieldLabel: 'Date hired',
                name: 'dateHired'
            }
        ]
    },
    {
        xtype: 'container',
        layout: 'form',
        title: 'Personal',
        style: 'padding:5px 5px 0',
        defaults: {
            xtype: 'textfield',
            width: 150
        },
        items: [
            {
                xtype: 'numberfield',
                fieldLabel: 'Age',
                name: 'age',
                width: 50,
                maskRe: /[0-9]/
            },
            {
                xtype: 'combo',
                name: 'gender',
                fieldLabel: 'Пол',
                store: new Ext.data.ArrayStore({
                    data: [
                        ['Мужской'],
                        ['Женский'],
                        ['Еще не определился']
                    ],
                    fields: ['gender']
                }),
                mode: 'local',
                displayField: 'gender',
                editable: false,
                triggerAction: 'all'
            },
            {
                fieldLabel: 'E-mail',
                name: 'humanEmail'
            }
        ]
    }
];

var tabPanel = {
    xtype: 'tabpanel',
    border: false,
    plain: true,
    deferredRender: false,
    activeTab: 0,
    flex: 1,
    items: tabs
};

var formPeople = new Ext.form.FormPanel({
    title: 'People information',
    id: 'formPeople',
    layout: 'vbox',
    height: 250,
    bodyStyle: 'padding: 5px',
    defaultType: 'textfield',

    defaults: {
        msgTarget: 'qtip',
        anchor: offsetAnchor
    },
    items: [
        {
            xtype: 'container',
            layout: 'form',
            defaults: {
                xtype: 'textfield',
                width: 150
            },
            items: [
                {
                    fieldLabel: 'Name',
                    name: 'name',
                    allowBlank: false


                }
            ]
        },
        tabPanel
    ]
});


//---------------------------------------------------------------
// Project Form
//---------------------------------------------------------------

var formProject = new Ext.form.FormPanel({
    title: 'Project information',
    bodyStyle: 'padding: 5px',
    id: 'formProject',

    defaultType: 'textfield',
    defaults: {
        msgTarget: 'qtip',
        anchor: offsetAnchor
    },
    items: [
        {
            fieldLabel: 'Name',
            name: 'name',
//            emptyText: 'This field is empty!',
            allowBlank: false
        }
    ]
});

//---------------------------------------------------------------
// Department Form
//---------------------------------------------------------------

var formDepartment = new Ext.form.FormPanel({
    title: 'Department information',
    bodyStyle: 'padding: 5px',
    id: 'formDepartment',

    defaultType: 'textfield',
    defaults: {
        msgTarget: 'qtip',
        anchor: offsetAnchor
    },
    items: [
        {
            fieldLabel: 'Name',
            name: 'name',
            //            emptyText: 'This field is empty!',
            allowBlank: false
        }
    ]
});

//---------------------------------------------------------------
// Organization Form
//---------------------------------------------------------------

var formOrganization = new Ext.form.FormPanel({
    title: 'Organization information',
    bodyStyle: 'padding: 5px',
    id: 'formOrganization',

    defaultType: 'textfield',
    defaults: {
        msgTarget: 'qtip',
        anchor: offsetAnchor
    },
    items: [
        {
            fieldLabel: 'Name',
            label: true,
            name: 'name',
            allowBlank: false

        }
    ]
});

//---------------------------------------------------------------
// Panel with the save button
//---------------------------------------------------------------

var saveButtonPanel = new Ext.form.FormPanel({
    frame: true,
    id: 'saveButtonPanel',
    items: {
        xtype: 'button',
        id: 'saveButton',
        text: 'сохранить'

    }
});
var saveButton = Ext.getCmp('saveButton');
saveButton.addListener('click', onButtonSaveClick);

//var peopleStore = new Ext.data.JsonStore({
//    root: 'people',
//    storeId: 'peopleStore',
//    url: '../Organization/loadHuman',
//    fields: [
//        {name: 'name', mapping: 'name'},
//        {name: 'id', mapping: 'id'},
//        {name: 'position', mapping: 'position'},
//        {name: 'age', mapping: 'age'},
//        {name: 'gender', mapping: 'gender'}
//    ]
//
//});